package com.changgou.goods.service.impl;

import com.changgou.goods.dao.BrandMapper;
import com.changgou.goods.pojo.Brand;
import com.changgou.goods.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/***
 * 描述
 * @author ljh
 * @packagename com.changgou.goods.service.impl
 * @version 1.0
 * @date 2020/5/5
 */
@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    private BrandMapper brandMapper;

    @Override
    public List<Brand> findAll() {
        //service 要调用dao 查询所有的数据
        return brandMapper.selectAll();
    }

    @Override
    public Brand findById(Integer id) {
        //select * from tb_brand where id=? //根据主键来查询
        return brandMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(Brand brand) {
        //update tb_brand set name=?,letter=?,image=? where id=?
        //brandMapper.updateByPrimaryKeySelective(brand)  根据主键更新  先判断如果字段为空则不更新
        //brandMapper.updateByPrimaryKey(brand);根据注解更新 ，不判断 传递什么数据就更新什么数据，比如传递了一个null 就会更新为Null.
        brandMapper.updateByPrimaryKeySelective(brand);
        //brandMapper.updateByPrimaryKey(brand);
    }
}
